package com.im.app.controller;

import com.im.app.model.YunConfig;
import com.im.app.service.IYunConfigService;
import com.im.app.utils.Response;
import com.im.app.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/config")
public class ConfigController {

    @Resource
    private IYunConfigService iYunConfigService;

    @GetMapping(value = "/getData")
    public ResponseResult<Object> queryYunConfigList() {
        //调用业务层返回列表
        List<YunConfig> yunConfigList = iYunConfigService.selectYunConfigList(new YunConfig());
        Map<String,Object> map = new HashMap<>();
        for (YunConfig yunConfig : yunConfigList) {
            if("apiUrl".equals(yunConfig.getDictKey())){
                map.put("apiUrl",yunConfig.getDictValue());
            }else if("ioUrl".equals(yunConfig.getDictKey())){
                map.put("ioUrl",yunConfig.getDictValue());
            }else if("ioPort".equals(yunConfig.getDictKey())){
                map.put("ioPort",Integer.valueOf(yunConfig.getDictValue()));
            }else if("uploadUrl".equals(yunConfig.getDictKey())){
                map.put("uploadUrl",yunConfig.getDictValue());
            }else if("version".equals(yunConfig.getDictKey())){
                map.put("version",yunConfig.getDictValue());
            }else if("updateAddress".equals(yunConfig.getDictKey())){
                map.put("updateAddress",yunConfig.getDictValue());
            }else if("down".equals(yunConfig.getDictKey())){
                map.put("down",yunConfig.getDictValue());
            }
        }
        return Response.makeOKRsp(map);
    }
}
